Rules

What is the rules

The HTTP Rules engine allows users to customize the CDN edge server behavior, e.g. how the CDN will manage cache and redirection. This creates a lot of flexibility and adaptability for different platform websites to integrate with CDN without much hassle.

How to set the rules

You can go to CDN Resources -> Rules to configure.

A condition consists of a subject, which determines the value to select, and a predicate, which specifies what to compare the subject against. Conditions are bonded by the connectives “AND” or “OR”. When all the conditions are met, the CDN edge server will perform the actions associated with the rule. The CDN edge server processes these rules from top to bottom order. It ends processing on the first match.

Subject

Subject Details
Default Matches all remaining requests. When used, it should be the last rule in the ruleset.
URL Selects the URL part of the request. It excludes the query string.
Example
Client requests:http://cdn.example.com/image.jpg
Selected value: /image.jpg
IP Selects the IP address of the client. If the clients use a proxy server, the IP of their proxy server which made the request to the edge server will be selected.
Example
192.0.2.43
Cookie Selects the value of a specific cookie sent by the client.
Example
Cookie chosen: logged_in
Client request header: Cookie: session_id=abcdef;logged_in=1; cart_id=defabc
Selected value: 1
Country Selects the client’s country. If the client’s country cannot be derived from their IP, the value “ ” is selected.
Example
Client’s IP: 193.113.9.162
Selected value: United Kingdom
Param Selects the value of a specific query string parameter. If there are multiple identical keys, the last value is selected.
Example
Parameter chosen: page
Client requests: http://cdn.example.com/index.php?page=about&id=53
Selected value: about
Extension Selects the file extension of the request. If the request filename does not contain a dot, then the value “ ” is selected.
Example
Client requests: http://cdn.example.com/image.jpg
Selected value: jpg
Header Selects the value of a specific client request header. If the request header does not exist, then the value “ ” is selected.
Example
Header chosen: User-Agent
Client sends header: User-Agent: Mozilla/5.0 (Windows NT 6.3) Firefox/30.0
Selected value: Mozilla/5.0 (Windows NT 6.3) Firefox/30.0
Scheme Selects the scheme part of the request. It can be either http or https.
Example
Client requests: http://cdn.example.com/image.jpg
Selected value: http

Example
Client requests: https://secure.example.com/image.jpg
Selected value: https

Predicates

Predicate Details
Equals Compares the subject to an exact value.

Example
URL /index.php
Equals /index.php
Result TRUE

URL /ExampleFile.txt
Equals /examplefile.txt
Result TRUE

URL /image.jpg
Equals /index.php
Result FALSE
Starts with Compares whether the subject starts with a value.

Example
IP 192.0.2.54
Starts With 192.0.2.
Result TRUE

URL /images/files.jpg
Starts With /images/
Result TRUE

IP 192.5.54.3
Starts With 192.0.2.
Result FALSE
Ends with Compares whether the subject ends with a value.

Example
URL /images/files.jpg
Ends With .jpg
Result TRUE

URL /videos/video.mp4
Ends With .jpg
Result FALSE
In List Compares the subject to the list of values. Each value is separated by a single space.

Example
Country GB
In List GB ES FR DE
Result TRUE

Country US
In List GB ES FR DE
Result FALSE
Matches wildcard Compares whether the subject matches a wildcard value. The wildcard character * matches any 0 or more characters. Multiple *s can be specified.

Example
Url /images/photos/photo.jpg
Matches Wildcard /images/ * .jpg
Result TRUE

Url /images/videos/video.mp4
Matches Wildcard /images/ * .jpg
Result FALSE

Url /archives/2014/news/index.html
Matches Wildcard / * /2014/news/ *
Result TRUE
Does not equal Opposite of the Equals value
Does not start with Opposite of the Starts with value
Does not end with Opposite of the Ends with value
Is not in list Opposite of the In list value
Does not match wildcard Opposite of the Matches wildcard value

Actions

Action Details
Cache rules
Force Edge To Never Cache Forces the CDN edge server to never cache the request. However, if the request is already cached (for example, if it was cached prior to setting up this rule), it will not be forced out of cache.
Force Client To Never Cache Forces the client to never cache the request. This is achieved by removing all Cache-Control and Expires response headers, sending instead Cache-Control: no-cache.
Force Edge To Cache Forces the CDN edge server to cache the request for a specified duration. This overrides any Cache-Control or Expires headers from the origin, even if they specify private or no-cache.The value must be 1 second or longer.
Force Client To Cache Forces the client to cache the request for a specified duration. This is achieved by removing all Cache-Control and Expires response headers, sending instead “Cache-Control: max-age=...”.The value must be 1 second or longer.
Override Default Cache Validity Changes the CDN edge server’s default validity period for origin responses that do not explicitly specify Cache-Control or Expires. Responses with Cache-Control or Expires headers are still honored.The value must be 1 second or longer.
Redict rules
Forbid Client Returns a simple 403 Forbidden response to the client.
Redirect Client from HTTP to HTTPs Returns a 301 Redirect response from http address to https address instead of loading from cache or upstream.
Redirect Client Returns a 302 Redirect response to the client, to the specified URL.The URL must be specified in full, starting with http:// or https://
Modify header
Set Request Header Overrides a request header to the origin. A header name and header value must be provided.
Set Response Header Overrides a response header to the client. A header name and header value must be provided.
Set Client IP In Request Header Sets the client’s IP address in a request header to the origin. A header name must be provided.
Origin rules
Prepend Origin Directory Prepends a directory to the URL when the edge server requests it from the origin.

Examples
Prepend origin directoryimages
Client requests to edge: http://cdn.example.com/photo.jpg
Edge requests to origin:http://cdn.example.com/images/photo.jpg

Prepend origin directory: /some/sub%20directory/
Client requests to edge: http://cdn.example.com/some/file.txt
Edge requests to origin:http://cdn.example.com/some/sub%20directory/some/file.txt

A value must be provided (it cannot be empty).
Leading and trailing slashes from the directory are automatically stripped.
Special characters, such as spaces, must be percent-encoded.
Set Custom Origin Overrides the origin that the edge server connects to.
Example
Resource has origin 3.3.3.3.
A rule is added such that if a URL starts with /images/, it sets a custom origin to 5.5.5.5.

A value must be provided (it cannot be empty) and it must be a valid hostname or IP.
A custom origin port cannot be specified or overridden.
“Set Request Header” may be used in conjunction with this to set a correct Host header.
Passthrough HTTP Host Header to Origin Goes back to the origin when the condition = true, during the first time, and the subsequent request (being cached in edge) will not go back to the origin again although the condition = true.
CDN edge server will only go back to the origin when the file does not exist (cache) in the edge server (for ALL scenario), and the feature "passthrough http host header to origin" happens during the path from cdn edge --> origin. This feature is not about "making all requests goes back to origin", but "sending the host header info to origin".
LightCDN all right reserved,powered by GitbookUpdated Time: 2024-01-11 15:19:50

results matching ""

    No results matching ""